﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using IMCOM.Imagiality.Core;

namespace IMCOM.Imagiality.MainGUI
{
    public class CameraSettingsGUI : Panel
    {
        private GroupBox groupBoxCameraSettings;
        private Panel panelGain;
        private Panel panelContrast;
        private Label labelGain;
        private Label labelContrast;
        private TrackBar trackbarGain;
        private TrackBar trackbarContrast;
        private Button buttonAuto;
        private IList<CameraSettingsGUIListener> listeners;

        public CameraSettingsGUI()
        {
            listeners = new List<CameraSettingsGUIListener>();

            Width = 150;
            Height = 150;

            groupBoxCameraSettings = new GroupBox();
            groupBoxCameraSettings.Text = "Camera Settings";

            Controls.Add(groupBoxCameraSettings);

            panelGain = new Panel();
            groupBoxCameraSettings.Controls.Add(panelGain);

            labelGain = new Label();
            panelGain.Controls.Add(labelGain);
            labelGain.Text = "Gain";
            labelGain.TextAlign = ContentAlignment.MiddleLeft;

            trackbarGain = new TrackBar();
            panelGain.Controls.Add(trackbarGain);
            trackbarGain.TickStyle = TickStyle.None;

            labelGain.Dock = DockStyle.Left;
            trackbarGain.Dock = DockStyle.Right;

            panelContrast = new Panel();
            groupBoxCameraSettings.Controls.Add(panelContrast);

            labelContrast = new Label();
            panelContrast.Controls.Add(labelContrast);
            labelContrast.Text = "Contrast";
            labelContrast.TextAlign = ContentAlignment.MiddleLeft;

            trackbarContrast = new TrackBar();
            panelContrast.Controls.Add(trackbarContrast);
            trackbarContrast.TickStyle = TickStyle.None;

            labelContrast.Dock = DockStyle.Left;
            trackbarContrast.Dock = DockStyle.Right;

            buttonAuto = new Button();
            buttonAuto.Text = "Auto";
            groupBoxCameraSettings.Controls.Add(buttonAuto);

            Resize += new EventHandler(GUIResized);

            ArrangeLayout();
        }

        public void AddListener(CameraSettingsGUIListener listener)
        {
            listeners.Add(listener);
        }

        private void GUIResized(object sender, System.EventArgs e)
        {
            ArrangeLayout();
        }

        private void ArrangeLayout()
        {
            groupBoxCameraSettings.Width = Width;
            groupBoxCameraSettings.Height = Height;

            panelGain.Location = new Point(5, 20);
            panelGain.Width = Width - 10;
            panelGain.Height = 30;

            labelGain.Width = (panelGain.Width / 2);
            trackbarGain.Width = (panelGain.Width / 2);

            panelContrast.Location = new Point(5, 20 + panelGain.Height + 5);
            panelContrast.Width = Width - 10;
            panelContrast.Height = 30;

            labelContrast.Width = (panelGain.Width / 2);
            trackbarContrast.Width = (panelGain.Width / 2);

            buttonAuto.Location = new Point(5, 20 + panelGain.Height + panelContrast.Height + 5);
            buttonAuto.Width = Width - 10;
        }
    }
}
